package inutan.robot;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class RobotTime {

    private static Map<String,Long> reqTimes = new ConcurrentHashMap<>();

    private static Map<Integer,Integer> nums = new ConcurrentHashMap<>();

    public static long time(String id) {
        Long reqTime = reqTimes.remove(id);
        if(reqTime == null) {
            System.err.println("hgjg");
        }
        return System.currentTimeMillis() - reqTime;
    }

    public static void req(int conv, int packId) {
        String id = conv +" - "+ packId;
        System.err.println(id +",正在加入请求消息");
        reqTimes.put(id,System.currentTimeMillis());
    }

    public static int reqLen () {
        reqTimes.forEach((k,v) -> System.err.println(k + " 消息丢失，发送时间 time:" + v));
        return reqTimes.size();
    }
    public static void addCount(int key) {
        int v = nums.computeIfAbsent(key,k -> 1 );
        nums.put(key, v + 1);
    }

    public static int getCount(int k) {
        return nums.getOrDefault(k,0);
    }
}
